package com.algorithm.string_and_array;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Stack;
import java.util.stream.Collectors;

@Slf4j
public class StringSolutionLC13 {
    public String reverseWords(String s) {
        String[] split = s.split("\\W");
        String result  = "";
        for (int i = split.length-1; i >= 0; i--) {
            String s1 = split[i];
            if (s1.trim().length()==0){
                continue;
            }
            result = result + split[i].trim()+" ";
        }
        return result.trim();
    }

    @Test
    public void test(){
        String s = "a good   example";
        String s1 = reverseWords(s);
        log.info("result is {}",s1);
    }


    public String reverseWords1(String s) {
        int i = 0;
        int j = s.length()-1;
        while (i<j){
            char tmp = s.charAt(i);
            //TODO 1中的空间复杂度太高了  考虑双指针发

        }

        return "".trim();
    }
}
